﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{
    public partial class FormReader : FormBase
    {
        public FormReader()
        {
            InitializeComponent();
        }

        public FormReader(ToolStripMenuItem tsMi):base(tsMi)
        {
            InitializeComponent();
        }

        private void FormStuInfo_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
            SqlDataReader reader = null;
            try
            {
                SqlCommand cmd = new SqlCommand();
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = @"select * from menu where menuname = @mn;
                                    select * from useraccount where username = @un;
                                    select * from tpstu where sno = @sn";
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@mn";
                param.Value = "人员信息管理";
                cmd.Parameters.Add(param);

                param = new SqlParameter();
                param.ParameterName = "@un";
                param.Value = "0001080";
                cmd.Parameters.Add(param);

                param = new SqlParameter();
                param.ParameterName = "@sn";
                param.Value = "201110801002";
                cmd.Parameters.Add(param);
                reader = cmd.ExecuteReader();
                //通用的结果集和记录遍历代码
                string fmt = "{0}   {1}    {2}   {3}";
                while (true)
                {
                    while (reader.Read())
                    {
                        listBox1.Items.Add(string.Format(fmt, reader[0], reader[1], reader[2], reader[3]));
                    }
                    if (!reader.NextResult())
                        break;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (reader != null)
                    reader.Close();
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }
    }
}
